benevolent union型
benevolent union型はPHPStanの型。PHPStanに実装された特殊ユニオン型であり、型理論として一般的な用語ではない。
「benevolent」は親切、善意、慈悲深い、事前、善行、公益、博愛、情け深いといった意味。
型安全性を故意に失わせて
PHPStanのLevel 7以上では string|false 型がついた項をstring型のみを受け入れる関数に渡すと警告する。
code:php
json_decode(file_get_contents('data.json'));
// Parameter #1 $json of function json_decode expects string, string|false given.
https://phpstan.org/r/71a5f06b-5511-4786-ae3e-0907f79b7003
一方、__benevolent<string|false>型がついた項は、同じく文字列を
array-key型は__benevolent<int|string>として実装されている。